package com.lightningtrade.service.impl;

import com.lightningtrade.domain.SysProduct;
import com.lightningtrade.mapper.SysProductMapper;
import com.lightningtrade.service.SysProductService;
import com.lightningtrade.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysProductServiceImpl implements SysProductService {

    @Autowired
    private SysProductMapper sysProductMapper;

    @Override
    public int addProduct(SysProduct sysProduct) {
        return sysProductMapper.insertProduct(sysProduct);
    }

    @Override
    public int updateProduct(SysProduct sysProduct) {
        return sysProductMapper.updateProduct(sysProduct);
    }

    @Override
    public int deleteProduct(Integer id) {
        return sysProductMapper.deleteProduct(id);
    }

    @Override
    public SysProduct getProductById(Integer id) {
        return sysProductMapper.selectProductById(id);
    }

    @Override
    public List<SysProduct> getAllProducts() {
        return sysProductMapper.selectAllProducts();
    }

    @Override
    public int updateProductStatus(Integer id, Integer status) {
        return sysProductMapper.updateProductStatus(id, status);
    }

    @Override
    public AjaxResult getProductByName(String productName) {
        List<SysProduct> sysProductList = sysProductMapper.selectProductByName(productName);
        if (sysProductList != null) {
            return AjaxResult.success("查询成功", sysProductList);
        }
        return AjaxResult.error("商品未找到");
    }
}
